import React, {Component, PropTypes} from 'react';

import { message, Button,Row,Col } from 'antd';
import moment from 'moment';

export default class Step4 extends Component {

  constructor (props) {
    super(props);
  }

  componentDidMount () {
  }

  /**
   * 下一步完成配置
   * @param formdata
   */
  handleFormOk () {
    const {examActions, exam} = this.props;
    examActions.postExamFinish({
      $loki : parseInt(this.props.params.$loki)
    }).then(data=>{
      this.props.router.push({
        pathname: '/examview/'+data.$loki
      });

    });
  }

  render() {

    const {exam} = this.props;
    const dateFormat = 'YYYY-MM-DD';
    const userlist = exam.get('userList') && exam.get('userList').toArray();
    const roomlist = exam.get('roomlist') && exam.get('roomlist').toArray();
    const examdetail = exam && exam.get('examdetail').toJS();

    let tfng = 0, single = 0, multiple = 0;
    examdetail.exam_questions.forEach(item=>{
      tfng += item.tfng_list.length;
      single += item.single_list.length;
      multiple += item.multiple_list.length;
    });

    return (
      <div className="ant-steps-wraper">
        <div className="steps-content">
          <h1>考试名称:{examdetail.exam_name}</h1>
          <Row>
            <Col span={16}>
              <ul className="ant-exam-info">
                <li>
                  开始时间:{moment(examdetail.exam_start_date,dateFormat).format('YYYY-MM-DD')} /
                  结束时间:{moment(examdetail.exam_end_date,dateFormat).format('YYYY-MM-DD')}
                </li>
                <li>出题类型:{examdetail.exam_qetype === '0' ? '题目相同' : '题目不同'}</li>
                <li>
                  考题信息:
                  <ul>
                    <li>单选题:{examdetail.exam_single.num}个*{examdetail.exam_single.score}分</li>
                    <li>多选题:{examdetail.exam_multiple.num}个*{examdetail.exam_multiple.score}分</li>
                    <li>判断题:{examdetail.exam_tfng.num}个*{examdetail.exam_tfng.score}分</li>
                  </ul>
                </li>

                <li>
                  导入统计:
                  <ul>
                    <li>考场总数:{roomlist.length}个</li>
                    <li>试题总数:单选{single}个,多选{multiple}个,判断{tfng}个</li>
                    <li>学员总数:{userlist.length}个</li>
                  </ul>
                </li>

                <Button type="primary" onClick={() => this.handleFormOk()}>生成考试</Button>

              </ul>
            </Col>

          </Row>
          
        </div>
      </div>
    )
  }

}

